package com.javasm.springmybatis.common.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

//spring容器静态化工具类
@Component
public class SpringContainerUtils implements ApplicationContextAware {

    //spring容器
    private static  ApplicationContext applicationContext ;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext1) throws BeansException {
        applicationContext =applicationContext1;
    }

    /**
     * 根据类型获取spring中的对象
     *
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> clazz){
        return applicationContext.getBean(clazz);
    }
}